import request from '@/utils/request'

// 查询域名白名单列表
export function listWhitelist(query) {
  return request({
    url: '/third-party/whitelist/management/list',
    method: 'get',
    params: query
  })
}

// 查询域名白名单详细
export function getWhitelist(whitelistId) {
  return request({
    url: '/third-party/whitelist/management/' + whitelistId,
    method: 'get'
  })
}

// 新增域名白名单
export function addWhitelist(data) {
  return request({
    url: '/third-party/whitelist/management',
    method: 'post',
    data: data
  })
}

// 修改域名白名单
export function updateWhitelist(data) {
  return request({
    url: '/third-party/whitelist/management',
    method: 'put',
    data: data
  })
}

// 删除域名白名单
export function delWhitelist(whitelistId) {
  return request({
    url: '/third-party/whitelist/management/' + whitelistId,
    method: 'delete'
  })
}

// 更新白名单状态
export function updateWhitelistStatus(whitelistIds, status) {
  return request({
    url: '/third-party/whitelist/management/status',
    method: 'put',
    data: {
      whitelistIds: whitelistIds,
      status: status
    }
  })
}

// 获取当前有效域名列表
export function getCurrentDomains() {
  return request({
    url: '/third-party/whitelist/management/domains',
    method: 'get'
  })
}

// 检查域名是否唯一
export function checkDomainUnique(domain) {
  return request({
    url: '/third-party/whitelist/management/checkDomainUnique',
    method: 'get',
    params: { domain }
  })
}

// 导出白名单
export function exportWhitelist(query) {
  return request({
    url: '/third-party/whitelist/management/export',
    method: 'post',
    data: query
  })
}

// 获取导入模板
export function importTemplate() {
  return request({
    url: '/third-party/whitelist/management/importTemplate',
    method: 'post'
  })
}

// 导入数据
export function importData(data, updateSupport) {
  return request({
    url: '/third-party/whitelist/management/importData?updateSupport=' + updateSupport,
    method: 'post',
    data: data
  })
}

// 获取白名单数据 (ThirdPartyController)
export function getWhitelistData(version) {
  return request({
    url: '/third-party/whitelist' + (version ? '?version=' + version : ''),
    method: 'get'
  })
}

// 发布白名单 (ThirdPartyController)
export function publishWhitelist(description) {
  return request({
    url: '/third-party/whitelist/publish',
    method: 'post',
    params: { description }
  })
}

// 发布自定义白名单 (ThirdPartyController)
export function publishCustomWhitelist(domains, description) {
  return request({
    url: '/third-party/whitelist/publish/custom',
    method: 'post',
    data: { domains, description }
  })
}

// 获取当前版本号 (ThirdPartyController)
export function getCurrentVersion() {
  return request({
    url: '/third-party/whitelist/version',
    method: 'get'
  })
}

// 获取所有版本 (ThirdPartyController)
export function getAllVersions() {
  return request({
    url: '/third-party/whitelist/versions',
    method: 'get'
  })
}

// 清空白名单缓存 (ThirdPartyController)
export function clearWhitelistCache() {
  return request({
    url: '/third-party/whitelist/cache',
    method: 'delete'
  })
}
